/**
 * 
 */
package com.yjpark;

import java.nio.*;

/**
 * @author absolujin
 * 
 */

enum MessageType {
	M_HELLO, M_BYE, M_CALCREQ, M_CALCRES, M_LOGREQ, M_LOGRES,
	M_LOGINREQ, M_LOGINRES
}

public class PacketHeader {
	private static int ProtocolName = 0xABCDEF00;
	private MessageType Type;
	private int Length;

	static int HEADER_SIZE = 12;

	public PacketHeader() {
	}

	public PacketHeader(MessageType type, int length) {
		this.Type = type;
		this.Length = length;
	}

	public PacketHeader(int type, int length) {
		switch (type) {
		case 1:
			this.Type = MessageType.M_HELLO;
			break;
		case 2:
			this.Type = MessageType.M_BYE;
			break;
		case 3:
			this.Type = MessageType.M_CALCREQ;
			break;
		case 4:
			this.Type = MessageType.M_CALCRES;
			break;
		case 5:
			this.Type = MessageType.M_LOGREQ;
			break;
		case 6:
			this.Type = MessageType.M_LOGRES;
			break;
		case 7:
			this.Type = MessageType.M_LOGINREQ;
			break;
		case 8:
			this.Type = MessageType.M_LOGINRES;
			break;
		}

		this.Length = length;
	}

	public static int getValue(MessageType type) {
		switch (type) {
		case M_HELLO:
			return 1;
		case M_BYE:
			return 2;
		case M_CALCREQ:
			return 3;
		case M_CALCRES:
			return 4;
		case M_LOGREQ:
			return 5;
		case M_LOGRES:
			return 6;
		case M_LOGINREQ:
			return 7;
		case M_LOGINRES:
			return 8;
		}

		return 0;
	}

	public static int getProtocolName() {
		return ProtocolName;
	}

	public void setProtocolName(int protocolName) {
		ProtocolName = protocolName;
	}

	public MessageType getType() {
		return Type;
	}

	public void setType(MessageType type) {
		Type = type;
	}

	public int getLength() {
		return Length;
	}

	public void setLength(int length) {
		Length = length;
	}

}
